package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.entity.vo.ChapterVO;
import com.woniu.pojo.Chapter;
import com.woniu.service.IChapterService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程章节表 前端控制器
 * </p>
 *
 * @author xiaotang
 * @since 2023-07-25
 */
@RestController
@RequestMapping("/chapter")
public class ChapterController {

    @Autowired
    private IChapterService chapterService;

    @Operation(summary = "根据课程ID查询章节及视频")
    @GetMapping("/relation/video/{courseId}")
    public Result<List<ChapterVO>> listByCourseIdRelationVideos(@PathVariable Long courseId){
        List<ChapterVO> chapterVOList = chapterService.listByCourseIdRelationVideos(courseId);
        return Result.ok(chapterVOList);
    }

    @PostMapping
    public Result addChapter(@RequestBody Chapter chapter){
        boolean flag = chapterService.save(chapter);
        return Result.ok(flag);
    }


}